{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "# from sklearn.tree import DecisionTreeClassifier\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "import numpy as np\n",
    "import sklearn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>肝素浓度</th>\n",
       "      <th>肝素IU浓度</th>\n",
       "      <th>ATP</th>\n",
       "      <th>ATPS酶加入量</th>\n",
       "      <th>3-ost加入量</th>\n",
       "      <th>反应时间</th>\n",
       "      <th>相对于t0的效价提升率</th>\n",
       "      <th>相对于初始投入的效价提升率</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20.00</td>\n",
       "      <td>1500.00</td>\n",
       "      <td>390.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>54.0</td>\n",
       "      <td>0.2211</td>\n",
       "      <td>0.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>1300.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>133.333333</td>\n",
       "      <td>66.0</td>\n",
       "      <td>-0.0104</td>\n",
       "      <td>-0.0120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.33</td>\n",
       "      <td>23.33</td>\n",
       "      <td>78.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>48.0</td>\n",
       "      <td>-0.0157</td>\n",
       "      <td>0.0500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>1950.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>66.666667</td>\n",
       "      <td>53.0</td>\n",
       "      <td>-0.0246</td>\n",
       "      <td>0.0328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.33</td>\n",
       "      <td>23.33</td>\n",
       "      <td>78.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>20.00</td>\n",
       "      <td>1500.00</td>\n",
       "      <td>390.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>72.0</td>\n",
       "      <td>0.1775</td>\n",
       "      <td>0.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>650.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>66.666667</td>\n",
       "      <td>24.0</td>\n",
       "      <td>-0.0987</td>\n",
       "      <td>-0.0456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>650.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>66.666667</td>\n",
       "      <td>72.0</td>\n",
       "      <td>-0.0987</td>\n",
       "      <td>-0.0456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0.33</td>\n",
       "      <td>23.33</td>\n",
       "      <td>78.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>54.0</td>\n",
       "      <td>0.0522</td>\n",
       "      <td>0.1224</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>20.00</td>\n",
       "      <td>1500.00</td>\n",
       "      <td>390.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0.0303</td>\n",
       "      <td>0.0000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>98 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     肝素浓度   肝素IU浓度     ATP  ATPS酶加入量    3-ost加入量  反应时间  相对于t0的效价提升率  \\\n",
       "0   20.00  1500.00   390.0      18.0   40.000000  54.0       0.2211   \n",
       "1   10.00   750.00  1300.0      60.0  133.333333  66.0      -0.0104   \n",
       "2    0.33    23.33    78.0       3.6    8.000000  48.0      -0.0157   \n",
       "3   10.00   750.00  1950.0      30.0   66.666667  53.0      -0.0246   \n",
       "4    0.33    23.33    78.0       3.6    8.000000   0.0       0.0000   \n",
       "..    ...      ...     ...       ...         ...   ...          ...   \n",
       "93  20.00  1500.00   390.0      18.0   40.000000  72.0       0.1775   \n",
       "94  10.00   750.00   650.0      30.0   66.666667  24.0      -0.0987   \n",
       "95  10.00   750.00   650.0      30.0   66.666667  72.0      -0.0987   \n",
       "96   0.33    23.33    78.0       3.6    8.000000  54.0       0.0522   \n",
       "97  20.00  1500.00   390.0      18.0   40.000000  48.0       0.0303   \n",
       "\n",
       "    相对于初始投入的效价提升率  \n",
       "0          0.0000  \n",
       "1         -0.0120  \n",
       "2          0.0500  \n",
       "3          0.0328  \n",
       "4          0.0667  \n",
       "..            ...  \n",
       "93         0.0000  \n",
       "94        -0.0456  \n",
       "95        -0.0456  \n",
       "96         0.1224  \n",
       "97         0.0000  \n",
       "\n",
       "[98 rows x 8 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据集载入\n",
    "data = pd.read_csv(\"dataset.csv\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     0.2211\n",
       "1    -0.0104\n",
       "2    -0.0157\n",
       "3    -0.0246\n",
       "4     0.0000\n",
       "       ...  \n",
       "93    0.1775\n",
       "94   -0.0987\n",
       "95   -0.0987\n",
       "96    0.0522\n",
       "97    0.0303\n",
       "Name: 相对于t0的效价提升率, Length: 98, dtype: float64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分离feature与Label，先只拿相对t0的效价提升率\n",
    "data_feature = data.iloc[:, 0:6]\n",
    "data_label_t0 = data.iloc[:, 6]\n",
    "data_label_t0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>肝素浓度</th>\n",
       "      <th>肝素IU浓度</th>\n",
       "      <th>ATP</th>\n",
       "      <th>ATPS酶加入量</th>\n",
       "      <th>3-ost加入量</th>\n",
       "      <th>反应时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>5200.0</td>\n",
       "      <td>240.0</td>\n",
       "      <td>533.333333</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.00</td>\n",
       "      <td>1500.00</td>\n",
       "      <td>156.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>62.5</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>30.00</td>\n",
       "      <td>2250.00</td>\n",
       "      <td>390.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>156.0</td>\n",
       "      <td>1.8</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>78.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>650.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>66.666667</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.33</td>\n",
       "      <td>23.33</td>\n",
       "      <td>78.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>70.2</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10.00</td>\n",
       "      <td>750.00</td>\n",
       "      <td>156.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    肝素浓度   肝素IU浓度     ATP  ATPS酶加入量    3-ost加入量  反应时间\n",
       "0  10.00   750.00  5200.0     240.0  533.333333    72\n",
       "1  20.00  1500.00   156.0       3.6    8.000000    66\n",
       "2  10.00   750.00    62.5       3.6    8.000000    48\n",
       "3  30.00  2250.00   390.0      18.0   40.000000    99\n",
       "4  10.00   750.00   156.0       1.8    4.000000     0\n",
       "5  10.00   750.00    78.0       3.6    8.000000    64\n",
       "6  10.00   750.00   650.0      30.0   66.666667     0\n",
       "7   0.33    23.33    78.0       3.6    8.000000    30\n",
       "8  10.00   750.00    70.2       3.6    8.000000    54\n",
       "9  10.00   750.00   156.0       3.6    8.000000    48"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取测试集\n",
    "datatest = pd.read_csv(\"datatest.csv\")\n",
    "datatest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 划分验证集与训练集， 使用随机森林回归分类器\n",
    "from sklearn.model_selection import cross_val_score\n",
    "from sklearn.ensemble import RandomForestRegressor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用均方根误差(RMSE)评价指标，结果显示相对来说比较少  均方根误差越小越好\n",
    "\n",
    "### 再使用R^2决定系数进行评估  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.09405710696252335"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regressor = RandomForestRegressor(n_estimators=100,random_state=0)\n",
    "score = cross_val_score(regressor, data_feature, data_label_t0, cv=10\n",
    "               ,scoring = \"neg_mean_squared_error\").mean()\n",
    "# sorted(sklearn.metrics.SCORERS.keys())#sklearn当中的模型评估指标（打分）列表\n",
    "score = np.sqrt(abs(score))\n",
    "score"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 对r2指标来说如果结果是0，就说明模型预测不能预测因变量。 如果结果是1。就说明是函数关系。 如果结果是0-1之间的数，就是我们模型的好坏程度。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.05943326793809885"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score_r2 = cross_val_score(regressor, data_feature, data_label_t0, cv=10\n",
    "               ,scoring = \"r2\").mean()\n",
    "score_r2  # ?????怎么会是呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████████| 50/50 [03:56<00:00,  4.73s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.09297503175403891\n",
      "160\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD4CAYAAADsKpHdAAAABHNCSVQICAgIfAhkiAA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q9cbGAZ8CBRHrx8Hruuq9QYmA2cCq9LmtbiuwN+BiYAB/we4qLljd/UWwjnAOnf/wN1rgEXA9A4uU964+2Z3fy2a3gusIfznmU44cRCNL4umpwOL3P2Qu38IrCO8R52OmQ0H/hvwQNrsLl1vMyshnCweBHD3GnffRRevd6QQKDazQqAX8DFdtN7u/jKwo9HsFtXVzIYCJe6+zEM6/C5tm6y6eiAMAzamva6K5nU5ZjYSGA8sB4a4+2YIoQEMjlbrSu/Hr4FbgaNp87p6vU8EqoGHoq6yB8ysN1283u6+Cbgb+AjYDOx29/9HF693Iy2t67BouvH8nLp6IGTqM+ty37M1s+OAJ4HZ7r4n16oZ5nW698PMLgG2uvvKuJtkmNfp6k24Sj4TuN/dxwOfEroPsukS9Y76y6cTukQ+B/Q2s2/k2iTDvE5X75iy1bVV70FXD4QqYETa6+GEpmaXYWbdCWHwiLs/Fc3eEjUZicZbo/ld5f04D/jvZrae0A34D2b2v+j69a4Cqtx9efT6PwkB0dXr/WXgQ3evdvda4ClgEl2/3ulaWteqaLrx/Jy6eiCsAMrMbJSZ9QCuAhZ3cJnyJvrWwIPAGnf/97RFi4EZ0fQM4Jm0+VeZWU8zGwWUEW48dSrufpu7D3f3kYR/0xfc/Rt0/Xp/Amw0s1OiWVOBt+ni9SZ0FX3BzHpFn/mphPtlXb3e6VpU16hbaa+ZfSF6z65N2ya7jr6jfgzu2F9M+PbN+8C/dHR58ly3LxKagW8CldFwMTAQeB54LxoPSNvmX6L3Yi0xvnXwWR+AC6j/llGXrzdQDlRE/+ZPA/0TUu+fA+8Aq4DfE75V0yXrDTxKuFdSS7jSv741dQUmRO/X+8B9RL9MkWvQT1eIiAjQ9buMREQkJgWCiIgACgQREYkoEEREBFAgiIhIRIEgIiKAAkFERCL/H6AJTCEmlzpPAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出学习曲线 n_estimators = 168暂定\n",
    "from tqdm import tqdm\n",
    "\n",
    "learnList = []\n",
    "for i in tqdm(range(1, 1000, 20)):\n",
    "    regressor = RandomForestRegressor(n_estimators= i ,random_state=0)\n",
    "    score = cross_val_score(regressor, data_feature, data_label_t0, cv=10\n",
    "               ,scoring = \"neg_mean_squared_error\").mean()\n",
    "    score = np.sqrt(abs(score))\n",
    "    learnList.append(score)\n",
    "#     print(i)\n",
    "\n",
    "print(min(learnList))\n",
    "print(20 * learnList.index(min(learnList)))\n",
    "plt.plot(range(1, 1000, 20), learnList, color='r', label='RandomForest')\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 定位到n_estimators = 168, 接下来使用网格搜索，对全局进行参数搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=10, estimator=RandomForestRegressor(random_state=450),\n",
       "             param_grid={'max_depth': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n",
       "                         'min_samples_leaf': [1, 6, 11, 16, 21, 26, 31, 36, 41,\n",
       "                                              46]})"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 网格搜索，寻找最优参数\n",
    "gini_threholds = np.linspace(0,0.5,50)\n",
    "\n",
    "#参数的取值范围\n",
    "parameters = {\n",
    "#                 \"criterion\":(\"gini\", \"entropy\")\n",
    "#               \"n_estimators\":[*range(100, 1000, 10)]\n",
    "#               ,\"splitter\":(\"best\",\"random\")\n",
    "              \"max_depth\":[*range(1,11)]\n",
    "              ,\"min_samples_leaf\":[*range(1,50,5)]\n",
    "#               ,\"min_impurity_decrease\":np.linspace(0,0.5,50)\n",
    "             }\n",
    "\n",
    "regressor = RandomForestRegressor(random_state=450)\n",
    "\n",
    "gs = GridSearchCV(regressor, parameters,cv=10)\n",
    "gs.fit(data_feature, data_label_t0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'max_depth': 3, 'min_samples_leaf': 1}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gs.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.08940825934501742"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gs.best_score_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 确定随机森林回归算法最优参数为：n_estimators = 168; max_depth = 3; min_samples_leaf = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.11256438,  0.12703523,  0.0651003 ,  0.14973409,  0.00658303,\n",
       "        0.17494707, -0.00157409,  0.02169354,  0.17793365,  0.07472438])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 输出预测结果\n",
    "regressor = RandomForestRegressor(n_estimators=168 ,random_state=480, max_depth=3, min_samples_leaf=1)\n",
    "\n",
    "regressor = regressor.fit(data_feature, data_label_t0,)\n",
    "score = regressor.score(data_feature, data_label_t0,)\n",
    "prediction = regressor.predict(datatest)\n",
    "# score\n",
    "prediction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "newResult = pd.DataFrame(prediction)\n",
    "newResult = pd.concat([datatest, newResult], axis=1)\n",
    "newResult.to_csv(\"newResultTest.csv\", encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 算法测试  XGBOOST （未调参数的结果比未调参数的随机森林差）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "score: 0.09935639037910798 R2: -0.13471215776778936\n",
      "预测结果: [ 0.15014139  0.13174586  0.01873773  0.12552118 -0.0016045   0.3166389\n",
      " -0.04261411  0.07117822  0.23019086  0.09013344]\n"
     ]
    }
   ],
   "source": [
    "# xgboost\n",
    "import xgboost as xgb\n",
    "\n",
    "xgbresult = xgb.XGBRegressor()\n",
    "xgbresult.fit(data_feature, data_label_t0)\n",
    "xgb_pred = xgbresult.predict(datatest)\n",
    "# xgb_pred\n",
    "\n",
    "score_xgb = cross_val_score(xgbresult, data_feature, data_label_t0, cv=10\n",
    "               ,scoring = \"neg_mean_squared_error\").mean()\n",
    "score_xgb_r2 = cross_val_score(xgbresult, data_feature, data_label_t0, cv=10\n",
    "               ,scoring = \"r2\").mean()\n",
    "# sorted(sklearn.metrics.SCORERS.keys())#sklearn当中的模型评估指标（打分）列表\n",
    "score_xgb = np.sqrt(abs(score_xgb))\n",
    "\n",
    "print(\"score:\", score_xgb, \"R2:\", score_xgb_r2)\n",
    "print(\"预测结果:\", xgb_pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 算法测试 SVM （未调参数的结果比未调参数的随机森林差）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "score: 0.09956898357686761 R2: -0.0865267382938221\n",
      "预测结果: [0.10253613 0.11786536 0.11385996 0.11831442 0.09125081 0.11668893\n",
      " 0.02360117 0.02471835 0.1147429  0.10416687]\n"
     ]
    }
   ],
   "source": [
    "# SVM\n",
    "from sklearn import svm\n",
    "\n",
    "svmResult = svm.SVR()\n",
    "svmResult.fit(data_feature, data_label_t0)\n",
    "svm_pred = svmResult.predict(datatest)\n",
    "\n",
    "score_svm = cross_val_score(svmResult, data_feature, data_label_t0, cv=10\n",
    "               ,scoring = \"neg_mean_squared_error\").mean()\n",
    "score_svm_r2 = cross_val_score(svmResult, data_feature, data_label_t0, cv=10\n",
    "               ,scoring = \"r2\").mean() \n",
    "\n",
    "score_svm = np.sqrt(abs(score_svm))\n",
    "\n",
    "print(\"score:\", score_svm, \"R2:\", score_svm_r2)\n",
    "print(\"预测结果:\", svm_pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 算法测试 深度前馈网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 待测试"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 模型融合 （加权表决融合)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.12341867,  0.12707713,  0.05777272,  0.13642651,  0.01796515,\n",
       "        0.21246799, -0.01105822,  0.03869257,  0.18482093,  0.08476782])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 效果不是很好，放弃这个尝试\n",
    "final_pred = 3/6 * prediction + 2/6 * xgb_pred + 1/6 * svm_pred\n",
    "final_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
